#include<iostream>
using namespace std;

int ans_arr[35][35];
int rem_arr[35][35];
int n;
int xx[4] = { 0,0,1,-1 };
int yy[4] = { 1,-1,0,0 };
void dfs(int x,int y)
{
	if (x<1 || y<1 || x>n || y>n || rem_arr[x][y])
		return;
	else {
		rem_arr[x][y] = 1;
		for (int i = 0; i < 4; i++)
			dfs(x + xx[i], y + yy[i]);
	}
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= n; j++) {
			cin >> ans_arr[i][j];
			rem_arr[i][j] = ans_arr[i][j];
		}
	for (int i = 1; i <= n; i++) {
		dfs(i, 1);
		dfs(1, i);
		dfs(n, i);
		dfs(i, n);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (rem_arr[i][j])cout << ans_arr[i][j] << " ";
			else cout << 2 << " ";
		}
		cout << endl;
	}
	return 0;
}